﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for Account
/// </summary>
public class AccountDAL
{
    DataAccess db;

	public AccountDAL()
	{
        db = new DataAccess();
    }

    public int InsertUpdateAccount(Account acc)
    {
        SqlParameter[] paraList = new SqlParameter[9];
        paraList[0] = new SqlParameter("@user_id", SqlDbType.Int);
        paraList[0].Value = acc.User_id;
        paraList[1] = new SqlParameter("@username", SqlDbType.NVarChar, 32);
        paraList[1].Value = acc.Username;
        paraList[2] = new SqlParameter("@password",SqlDbType.VarChar,32);
        paraList[2].Value = acc.Password;
        paraList[3] = new SqlParameter("@user_group_id",SqlDbType.Int);
        paraList[3].Value = acc.User_group_id;
        paraList[4] = new SqlParameter("@email",SqlDbType.NVarChar, 32);
        paraList[4].Value = acc.Email;
        paraList[5] = new SqlParameter("@first_name", SqlDbType.NVarChar, 32);
        paraList[5].Value = acc.First_name;
        paraList[6] = new SqlParameter("@last_name", SqlDbType.NVarChar, 32);
        paraList[6].Value = acc.Last_name;
        paraList[7] = new SqlParameter("@phone", SqlDbType.VarChar, 20);
        paraList[7].Value = acc.Phone;
        paraList[8] = new SqlParameter("@status", SqlDbType.Bit);
        paraList[8].Value = acc.Status;
        return db.executeUpdate("IS_Account",paraList);

    }
    public DataTable Login(string username, string password) 
    {
        SqlParameter[] paraList = new SqlParameter[2];
        paraList[0] = new SqlParameter("@username", SqlDbType.NVarChar, 32);
        paraList[0].Value = username;
        paraList[1] = new SqlParameter("@password",SqlDbType.VarChar,32);
        paraList[1].Value = password;
        return db.executeSelect("Login", paraList);
    }
    public DataTable getAccountByID(int user_id) 
    {
        SqlParameter[] paraList = new SqlParameter[3];
        paraList[0] = new SqlParameter("@user_id", SqlDbType.Int);
        paraList[0].Value = user_id;
        paraList[1] = new SqlParameter("@username", SqlDbType.NVarChar, 32);
        paraList[1].Value = null;
        paraList[2] = new SqlParameter("@password",SqlDbType.VarChar,32);
        paraList[2].Value = null;
        return db.executeSelect("Select_Account", paraList);
    }
    public DataTable getAccountByUserName(string username)
    {

        SqlParameter[] paraList = new SqlParameter[3];
        paraList[0] = new SqlParameter("@user_id", SqlDbType.Int);
        paraList[0].Value = 0;
        paraList[1] = new SqlParameter("@username", SqlDbType.NVarChar, 32);
        paraList[1].Value = username;
        paraList[2] = new SqlParameter("@password",SqlDbType.VarChar,32);
        paraList[2].Value = null;
        return db.executeSelect("Select_Account", paraList);
    }
    public DataTable getAccountAll() 
    {
        return db.executeSelect("Select_Account");
    }


}
    
